package com.lagou.serializer;

import com.alibaba.fastjson.JSON;

import java.io.IOException;

/**
 * @author 13771
 * @date 2020/8/31 17:58
 * @description
 */
public class JSONSerializer implements Serializer {

    //Java对象转换成二进制
    public byte[] serialize(Object object) throws IOException {
        return JSON.toJSONBytes(object);
    }

    //二进制转换成java对象
    public <T> T deserialize(Class<T> clazz, byte[] bytes) throws IOException {
        return JSON.parseObject(bytes, clazz);
    }
}
